import req from '@/utils/request';
import * as URL from '@/constants/api';

// 获取新闻列表
export function getNewsList (id) {
  return req({
    url: URL.NEWS_LIST,
    params: {
      channel_id: id,
      timestamp: Date.now(),
    },
  })
  .then(res => res.data.data.results);
}

// 获取用户频道列表
export function getChannelList () {
  return req({
    url: URL.CHANNEL_LIST,
  })
  .then(res => res.data.data.channels);
}

// 获取全部频道列表
export function getAllChannelList () {
  return req({
    url: URL.ALL_CHANNEL_LIST,
  })
  .then(res => res.data.data.channels);
}

// 重置用户频道列表
export function setChannelList (channelList) {
  return req({
    url: URL.CHANNEL_LIST,
    method: 'put',
    data: {
      channels: channelList, // { id: string, seq: string }[]
    },
  });
}
